<?php
use yii\widgets\ActiveForm;
use yii\helpers\Html;
?>
<?php $form = ActiveForm::begin(); ?>
    <table width="100%" class="table-form" id="add_student" data-left_count="<?=$left_count?>">
        <tr style="display: none">
            <th width="80" align="right"><?= $model->attributeLabels()['ids']; ?></th>
            <td><?= $form->field($model, 'ids', ['template' => '{input}{error}'])->hiddenInput(); ?></td>
        </tr>
    </table>
    <div style="display: none"><?= Html::submitButton('提交', ['id' => 'dosubmit']) ?></div>
<?php ActiveForm::end(); ?>
    <table id="data-load" class="easyui-datagrid" style="width: 100%"
           data-options="fitColumns:true,
       title:'<?= \yii\helpers\Html::encode($this->context->menu_current['name']); ?>',
       rownumbers: true,
       singleSelect:false,
       checkbox:true,
       idField: 'id',
       toolbar:'#toolbar'">
        <thead>
        <tr>
            <th data-options="field:'ck',checkbox:true,align:'center'"></th>
            <th data-options="field:'id',hidden:'true',align:'center'"><?= \Yii::t('zhtfrontend', 'id'); ?></th>
            <th data-options="field:'student_name',align:'center'"><?= \Yii::t('zhtfrontend', '学生姓名'); ?></th>
            <th data-options="field:'age',align:'center'"><?= \Yii::t('zhtfrontend', '年龄'); ?></th>
            <th data-options="field:'customer_name',align:'center'"><?= \Yii::t('zhtfrontend', '家长姓名'); ?></th>
            <th data-options="field:'tel',align:'center'"><?= \Yii::t('zhtfrontend', '电话号码'); ?></th>
            <th data-options="field:'card_id',align:'center'"><?= \Yii::t('zhtfrontend', '卡号'); ?></th>
        </tr>
        </thead>
    </table>
<?= $this->renderFile('@app/views/layouts/script_data.php'); ?>
<?php
$js = <<<JS
    $('#dosubmit').click(function(){
        var ids = '';
        $(".datagrid-view2 tbody").find('.datagrid-row-checked').each(function () {
            var val = $(this).find("td[field=id]>div").html();
            (ids == '') ? ids = val : ids += ',' + val;
        });
        var array = ids.split (",");
        if(ids==''){
            alert('请选择上课学生'); return false;
        }
        var left_count=$('#add_student').data('left_count');
        if(left_count==null){
            alert('最大人数数据缺失，无法增加学员！'); return false;
        }
        if(parseInt(left_count)<=0){
            alert('该班学员已满，无法增加学员！'); return false;
        }
        if(array.length>left_count){
            alert("可以增加"+left_count+"名学员，所选人数已超出！"); return false;
        }
        else{
            $('.table-form').find('#classmanage-ids').val(ids);
        }
    })
JS;
$this->registerJS($js);
?>